package hczc.longcai.com.hccrowdfunding.home.fourth_mine.activities;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.activity.BaseActivity;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.fragments.AttenFqxmFragment;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.fragments.AttenScxmFragment;

public class AttentionPeopleDetailsActivity extends BaseActivity implements View.OnClickListener {


    private ViewPager viewPager;
    private AttenFqxmFragment attenFqxmFragment;
    private AttenScxmFragment attenScxmFragment;

    private List<Fragment> list;
    private AttAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attention_people_details);

        initFragments();
        initViews();

    }

    private void initFragments() {
        list = new ArrayList<>();
        attenFqxmFragment = new AttenFqxmFragment();
        list.add(attenFqxmFragment);
        attenScxmFragment = new AttenScxmFragment();
        list.add(attenScxmFragment);
    }

    private void initViews() {

        findViewById(R.id.head_back).setOnClickListener(this);
        ((TextView) findViewById(R.id.head_title)).setText("          ");
        findViewById(R.id.headbar_background).setBackgroundColor(Color.parseColor("#00000000"));

        findViewById(R.id.mine_attention_people_details_scxm).setOnClickListener(this);
        findViewById(R.id.mine_attention_people_details_fqxm).setOnClickListener(this);

        viewPager = ((ViewPager) findViewById(R.id.mine_attention_people_details_viewpager));
        adapter = new AttAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);

    }

    class AttAdapter extends FragmentPagerAdapter{

        public AttAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.head_back:
                finish();
                break;
            case R.id.mine_attention_people_details_scxm:
                viewPager.setCurrentItem(1);
                break;
            case R.id.mine_attention_people_details_fqxm:
                viewPager.setCurrentItem(0);
                break;

        }
    }
}
